#pragma once
#include "common.h"
#ifdef _WIN64
#include <windows.h>
#elif _WIN32
#include <windows.h>
// #elif
// Linux
#endif

class PageCache
{
public:
    static PageCache *GetInstance()
    {
        return &_Inst;
    }

    Span *NewSpan(size_t size);
    void SpnaGiveBackPage(Span *span);
    Span *MapObjToSpan(void *ptr);
    static inline void Lock()
    {
        _mtx.lock();
    }
    static inline void UnLock()
    {
        _mtx.unlock();
    }
private:
    // 单例饿汉模式
    PageCache()
    {
    }
    PageCache(const PageCache &obj) = delete;

    SpanList _spanLists[NPAGES];
    // static std::unordered_map<PageId_t, Span *> _idSpanMap;
    static std::map<PageId_t, Span *> _idSpanMap;

    static PageCache _Inst;
    static std::recursive_mutex _mtx;

    static ObjectPool<Span> SpanPool; 
};